package org.gingresosapi.persistencia;

import org.gingresosapi.beans.Regimenremolques;
import java.sql.Date; 
import org.gingresosapi.beans.*;
import org.gingresosapi.controller.*;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
 import javax.sql.DataSource;
import org.gingresosapi.generales.Mensajeria;
import org.gingresosapi.generales.DataGManager;


/**
*
* @author
*/

public class RegimenremolquesPersistencia implements Serializable {
private static final long serialVersionUID = 1L;
public static Exception excepcion;
public static boolean esMensaje = false;
public static Connection con = null;
public static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/gingresosapi/properties/mensajes");
static DataGManager dataGManager;
static List<Regimenremolques> list;

public RegimenremolquesPersistencia(){
         esMensaje =false;
}


/**
*
* insert()
*/

public static boolean insert (Regimenremolques regimenremolques ) {
  excepcion = null;
  try {
      esMensaje =false;
   
   
   

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pinsert = null;
      String sql = "insert into regimenremolques(idremolque,idregimen,valor,periodopago,mespago,fechainscripcion,idusuario,fecha,activo,idmunicipio)  values(?,?,?,?,?,?,?,?,?,?)";
      pinsert = con.prepareStatement(sql);
              pinsert.setLong(1,regimenremolques.getIdremolque());
        pinsert.setString(2,regimenremolques.getIdregimen());
        pinsert.setDouble(3,regimenremolques.getValor());
        pinsert.setString(4,regimenremolques.getPeriodopago());
        pinsert.setString(5,regimenremolques.getMespago());
        pinsert.setDate(6,regimenremolques.getFechainscripcion());
        pinsert.setString(7,regimenremolques.getIdusuario());
        pinsert.setDate(8,regimenremolques.getFecha());
        pinsert.setString(9,regimenremolques.getActivo());
        pinsert.setString(10,regimenremolques.getIdmunicipio());
      int filas= pinsert.executeUpdate();
      pinsert.close();
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
 }


/**
*
* update()
*/

public static boolean update(Regimenremolques regimenremolques ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update regimenremolques set  idremolque=?, idregimen=?, valor=?, periodopago=?, mespago=?, fechainscripcion=?, idusuario=?, fecha=?, activo=?, idmunicipio=?  where  idremolque ='"+regimenremolques.getIdremolque()+"' and  idregimen ='"+regimenremolques.getIdregimen()+"' and  activo ='"+regimenremolques.getActivo()+"' and  idmunicipio ='"+regimenremolques.getIdmunicipio()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setLong(1,regimenremolques.getIdremolque());
pupdate.setString(2,regimenremolques.getIdregimen());
pupdate.setDouble(3,regimenremolques.getValor());
pupdate.setString(4,regimenremolques.getPeriodopago());
pupdate.setString(5,regimenremolques.getMespago());
pupdate.setDate(6,regimenremolques.getFechainscripcion());
pupdate.setString(7,regimenremolques.getIdusuario());
pupdate.setDate(8,regimenremolques.getFecha());
pupdate.setString(9,regimenremolques.getActivo());
pupdate.setString(10,regimenremolques.getIdmunicipio());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* update()
*/

public static boolean update(String sqlupdate ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update  regimenremolques set " + sqlupdate +"";
      pupdate= con.prepareStatement(sql);
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public static boolean updatePrimaryKey(Regimenremolques regimenremolques_old , Regimenremolques regimenremolques) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update regimenremolques set  idremolque=? ,  idregimen=? ,  activo=? ,  idmunicipio=?  where  idremolque ='"+regimenremolques_old.getIdremolque()+"' and  idregimen ='"+regimenremolques_old.getIdregimen()+"' and  activo ='"+regimenremolques_old.getActivo()+"' and  idmunicipio ='"+regimenremolques_old.getIdmunicipio()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setLong(1,regimenremolques.getIdremolque());pupdate.setString(2,regimenremolques.getIdregimen());pupdate.setString(9,regimenremolques.getActivo());pupdate.setString(10,regimenremolques.getIdmunicipio());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(Regimenremolques regimenremolques ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from regimenremolques  where  idremolque = ? and  idregimen = ? and  activo = ? and  idmunicipio = ?  ";
      pdelete= con.prepareStatement(sql);
      pdelete.setLong(1,regimenremolques.getIdremolque());
pdelete.setString(2,regimenremolques.getIdregimen());
pdelete.setString(9,regimenremolques.getActivo());
pdelete.setString(10,regimenremolques.getIdmunicipio());
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(String sqldelete ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from regimenremolques where " + sqldelete +"";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* deleteAll()
*/

public static boolean deleteAll() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from regimenremolques  ";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodeleteall"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* exists()
*/



public static boolean exists(Regimenremolques regimenremolques) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      String sql = "select * from regimenremolques where idremolque='"+regimenremolques.getIdremolque()+"' and idregimen='"+regimenremolques.getIdregimen()+"' and activo='"+regimenremolques.getActivo()+"' and idmunicipio='"+regimenremolques.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +" " + bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return false;
   }
    rs.close();
    psquery.close();
 return true;
} catch (Exception ex) {
      excepcion = ex;
}
  return false;
}


/**
*
* findByPrimaryKey()
*/



public static Regimenremolques findByPrimaryKey(Regimenremolques regimenremolques) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      String sql = "select * from regimenremolques where idremolque='"+regimenremolques.getIdremolque()+"' and idregimen='"+regimenremolques.getIdregimen()+"' and activo='"+regimenremolques.getActivo()+"' and idmunicipio='"+regimenremolques.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
            
            
            regimenremolques.setIdremolque(rs.getLong("idremolque"));
regimenremolques.setIdregimen(rs.getString("idregimen"));
regimenremolques.setValor(rs.getDouble("valor"));
regimenremolques.setPeriodopago(rs.getString("periodopago"));
regimenremolques.setMespago(rs.getString("mespago"));
regimenremolques.setFechainscripcion(rs.getDate("fechainscripcion"));
regimenremolques.setIdusuario(rs.getString("idusuario"));
regimenremolques.setFecha(rs.getDate("fecha"));
regimenremolques.setActivo(rs.getString("activo"));
regimenremolques.setIdmunicipio(rs.getString("idmunicipio"));
    }
    rs.close();
    psquery.close();
 return regimenremolques;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdremolque()
*/

public static List<Regimenremolques> findByIdremolque(Regimenremolques regimenremolques,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimenremolques>();
      String sql = "select * from regimenremolques where idremolque='"+regimenremolques.getIdremolque()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimenremolques regimenremolques2 = new Regimenremolques(
         rs.getLong("idremolque"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimenremolques2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdregimen()
*/

public static List<Regimenremolques> findByIdregimen(Regimenremolques regimenremolques,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimenremolques>();
      String sql = "select * from regimenremolques where idregimen='"+regimenremolques.getIdregimen()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimenremolques regimenremolques2 = new Regimenremolques(
         rs.getLong("idremolque"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimenremolques2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByValor()
*/

public static List<Regimenremolques> findByValor(Regimenremolques regimenremolques,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimenremolques>();
      String sql = "select * from regimenremolques where valor='"+regimenremolques.getValor()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimenremolques regimenremolques2 = new Regimenremolques(
         rs.getLong("idremolque"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimenremolques2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByPeriodopago()
*/

public static List<Regimenremolques> findByPeriodopago(Regimenremolques regimenremolques,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimenremolques>();
      String sql = "select * from regimenremolques where periodopago='"+regimenremolques.getPeriodopago()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimenremolques regimenremolques2 = new Regimenremolques(
         rs.getLong("idremolque"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimenremolques2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByMespago()
*/

public static List<Regimenremolques> findByMespago(Regimenremolques regimenremolques,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimenremolques>();
      String sql = "select * from regimenremolques where mespago='"+regimenremolques.getMespago()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimenremolques regimenremolques2 = new Regimenremolques(
         rs.getLong("idremolque"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimenremolques2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFechainscripcion()
*/

public static List<Regimenremolques> findByFechainscripcion(Regimenremolques regimenremolques,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimenremolques>();
      String sql = "select * from regimenremolques where fechainscripcion='"+regimenremolques.getFechainscripcion()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimenremolques regimenremolques2 = new Regimenremolques(
         rs.getLong("idremolque"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimenremolques2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdusuario()
*/

public static List<Regimenremolques> findByIdusuario(Regimenremolques regimenremolques,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimenremolques>();
      String sql = "select * from regimenremolques where idusuario='"+regimenremolques.getIdusuario()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimenremolques regimenremolques2 = new Regimenremolques(
         rs.getLong("idremolque"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimenremolques2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFecha()
*/

public static List<Regimenremolques> findByFecha(Regimenremolques regimenremolques,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimenremolques>();
      String sql = "select * from regimenremolques where fecha='"+regimenremolques.getFecha()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimenremolques regimenremolques2 = new Regimenremolques(
         rs.getLong("idremolque"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimenremolques2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByActivo()
*/

public static List<Regimenremolques> findByActivo(Regimenremolques regimenremolques,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimenremolques>();
      String sql = "select * from regimenremolques where activo='"+regimenremolques.getActivo()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimenremolques regimenremolques2 = new Regimenremolques(
         rs.getLong("idremolque"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimenremolques2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdmunicipio()
*/

public static List<Regimenremolques> findByIdmunicipio(Regimenremolques regimenremolques,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimenremolques>();
      String sql = "select * from regimenremolques where idmunicipio='"+regimenremolques.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimenremolques regimenremolques2 = new Regimenremolques(
         rs.getLong("idremolque"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimenremolques2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* locateByParameters()
*/

public static List<Regimenremolques> locateByParameters(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimenremolques>();
  String sql = "select * from regimenremolques";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      int i = 0;
      while (it.hasNext()) {
          if (i != 0){
            sb.append(" and ");
         }
         i++;
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"= '"+  e.getValue()+"'");
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimenremolques regimenremolques2 = new Regimenremolques(
         rs.getLong("idremolque"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimenremolques2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* Double fFunc(String funcion, String campo)
*/



public static Double func(String funcion, String campo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from regimenremolques";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* Double func(String funcion, String campo,String where)
*/



public static Double func(String funcion, String campo, String where) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from regimenremolques where "+where +" ";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* count()
*/



public static Integer count() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from regimenremolques";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* count(String sqlquery)
*/



public static Integer count(String sqlquery) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from regimenremolques where  " + sqlquery +"";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* query()
*/

public static List<Regimenremolques> query(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<Regimenremolques>();
  String sql = "select * from regimenremolques where " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimenremolques regimenremolques2 = new Regimenremolques(
         rs.getLong("idremolque"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimenremolques2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* getListRecords()
*/

public static List<Regimenremolques> getListRecords(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      list = new ArrayList<Regimenremolques>();
  String sql = "select * from regimenremolques";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"="+  e.getValue());
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimenremolques" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
       
        Regimenremolques regimenremolques2 = new Regimenremolques(
         rs.getLong("idremolque"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimenremolques2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
 }


}
